package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.shop.ShopMemberBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopMemberDto;
import com.ddwl.schema.vo.shop.ShopVo;
import com.ddwl.shop.service.ShopMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 加盟店接口
 * @author wenbin
 */
@Api(tags = "加盟店接口")
@RequestMapping("/shopMember")
@RestController
public class ShopMemberController extends BaseController {

    @Resource
    private ShopMemberService shopMemberService;

    @PostMapping("/createMemberShop")
    @ApiOperation("创建加盟店")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo createMemberShop(@RequestBody ShopMemberBo bo) {
        bo.setUserId(getUserId());
        bo.setShopId(getShopId());
        shopMemberService.create(bo);
        return RestVo.ok();
    }



    @DeleteMapping("/deleteMemberShop/{id}")
    @ApiOperation("删除加盟店")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo deleteMemberShop(@PathVariable("id") String id) {
        shopMemberService.delete(id);
        return RestVo.ok();
    }


    @GetMapping("/memberShopList")
    @ApiOperation("授权门店列表")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<List<ShopMemberDto>> shopList() {
        List<ShopMemberDto> list = shopMemberService.getShopList(getUserId());
        return RestVo.ok(list);
    }

    @GetMapping("/parentShopList")
    @ApiOperation("上级门店列表")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<List<ShopMemberDto>> parentShopList() {
        List<ShopMemberDto> list = shopMemberService.getParentShopList(getUserId());
        return RestVo.ok(list);
    }

    @PostMapping("/checkMemberShop")
    @ApiOperation("校验是否授权操作")
    @Auth(product = {BaseEnum.ProductEnum.API})
    public RestVo<ShopVo> checkMemberShop(@RequestParam String shopId,@RequestParam String memberShopId) {
        return RestVo.ok(shopMemberService.checkMemberShop(shopId,memberShopId));
    }

}
